package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ProductSalesOriginal;
import java.util.List;

/**
 * 对象功能: 产品开发费用登记adapter
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2016/6/15 11:12
 */
public class ProductDevelopListAdapter
    extends ArrayAdapter<ProductSalesOriginal.ProductSalesContent> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-04-25 10:39:46 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final LinearLayout llHolderOneSimpleList;
    public final TextView tvTitleOneSimpleList;
    public final TextView tvContentOneSimpleList;
    public final LinearLayout llHolderTwoSimpleList;
    public final TextView tvTitleTwoSimpleList;
    public final TextView tvContentTwoSimpleList;
    public final LinearLayout llHolderThreeSimpleList;
    public final TextView tvTitleThreeSimpleList;
    public final TextView tvContentThreeSimpleList;
    public final LinearLayout llHolderFourSimpleList;
    public final TextView tvTitleFourSimpleList;
    public final TextView tvContentFourSimpleList;
    public final TextView tvStatus;

    private ViewHolder(LinearLayout rootView, LinearLayout llHolderOneSimpleList,
        TextView tvTitleOneSimpleList, TextView tvContentOneSimpleList,
        LinearLayout llHolderTwoSimpleList, TextView tvTitleTwoSimpleList,
        TextView tvContentTwoSimpleList, LinearLayout llHolderThreeSimpleList,
        TextView tvTitleThreeSimpleList, TextView tvContentThreeSimpleList,
        LinearLayout llHolderFourSimpleList, TextView tvTitleFourSimpleList,
        TextView tvContentFourSimpleList, TextView tvStatus) {
      this.rootView = rootView;
      this.llHolderOneSimpleList = llHolderOneSimpleList;
      this.tvTitleOneSimpleList = tvTitleOneSimpleList;
      this.tvContentOneSimpleList = tvContentOneSimpleList;
      this.llHolderTwoSimpleList = llHolderTwoSimpleList;
      this.tvTitleTwoSimpleList = tvTitleTwoSimpleList;
      this.tvContentTwoSimpleList = tvContentTwoSimpleList;
      this.llHolderThreeSimpleList = llHolderThreeSimpleList;
      this.tvTitleThreeSimpleList = tvTitleThreeSimpleList;
      this.tvContentThreeSimpleList = tvContentThreeSimpleList;
      this.llHolderFourSimpleList = llHolderFourSimpleList;
      this.tvTitleFourSimpleList = tvTitleFourSimpleList;
      this.tvContentFourSimpleList = tvContentFourSimpleList;
      this.tvStatus = tvStatus;
    }

    public static ViewHolder create(LinearLayout rootView) {
      LinearLayout llHolderOneSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderOne_simpleList);
      TextView tvTitleOneSimpleList = (TextView) rootView.findViewById(R.id.tv_titleOne_simpleList);
      TextView tvContentOneSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentOne_simpleList);
      LinearLayout llHolderTwoSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderTwo_simpleList);
      TextView tvTitleTwoSimpleList = (TextView) rootView.findViewById(R.id.tv_titleTwo_simpleList);
      TextView tvContentTwoSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentTwo_simpleList);
      LinearLayout llHolderThreeSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderThree_simpleList);
      TextView tvTitleThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleThree_simpleList);
      TextView tvContentThreeSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentThree_simpleList);
      LinearLayout llHolderFourSimpleList =
          (LinearLayout) rootView.findViewById(R.id.ll_holderFour_simpleList);
      TextView tvTitleFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_titleFour_simpleList);
      TextView tvContentFourSimpleList =
          (TextView) rootView.findViewById(R.id.tv_contentFour_simpleList);
      TextView tvStatus = (TextView) rootView.findViewById(R.id.tv_planStatus);
      return new ViewHolder(rootView, llHolderOneSimpleList, tvTitleOneSimpleList,
          tvContentOneSimpleList, llHolderTwoSimpleList, tvTitleTwoSimpleList,
          tvContentTwoSimpleList, llHolderThreeSimpleList, tvTitleThreeSimpleList,
          tvContentThreeSimpleList, llHolderFourSimpleList, tvTitleFourSimpleList,
          tvContentFourSimpleList, tvStatus);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_recept_status_detail, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    ProductSalesOriginal.ProductSalesContent item = getItem(position);

    //        vh.tvTitleOneSimpleList.setText(R.string.cutomer_colon);
    vh.tvTitleOneSimpleList.setVisibility(View.GONE);
    vh.tvContentOneSimpleList.setText(item.getCustomer());//客户

    //        vh.tvTitleTwoSimpleList.setText(R.string.salesProduct);//产品
    vh.tvTitleTwoSimpleList.setVisibility(View.GONE);//产品
    if (!TextUtils.isEmpty(item.getProductKind())) {
      vh.tvContentTwoSimpleList.setText(item.getProductKind() + "  " + item.getProduct());//类型+产品
    } else {
      vh.tvContentTwoSimpleList.setText(item.getProduct());//类型+产品
    }

    vh.tvTitleThreeSimpleList.setText(R.string.develop_cost);//数量
    vh.tvContentThreeSimpleList.setText(item.getDevelopCost());//数量值
    vh.tvTitleThreeSimpleList.setTextColor(
        getContext().getResources().getColor(R.color.chocolate));//数量
    vh.tvContentThreeSimpleList.setTextColor(
        getContext().getResources().getColor(R.color.chocolate));//数量值

    vh.tvTitleFourSimpleList.setText(item.getInMonth());//时间
    vh.tvContentFourSimpleList.setText(item.getSalesManName());//业务员
    vh.tvTitleFourSimpleList.setTextColor(
        getContext().getResources().getColor(R.color.gray_Customerneed_tvTextColor));//时间
    vh.tvContentFourSimpleList.setTextColor(
        getContext().getResources().getColor(R.color.gray_Customerneed_tvTextColor));//业务员

    String dataStatus = item.getDataStatus();
    vh.tvStatus.setText(item.getDataStatus());
    //        if ("草稿".equals(dataStatus)) {
    //            vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.white));
    //            vh.tvStatus.setBackgroundColor(getContext().getResources().getColor(R.color.red));
    //        } else if ("已提交".equals(dataStatus)) {
    //            vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.white));
    //            vh.tvStatus.setBackgroundColor(getContext().getResources().getColor(R.color.blue_textColor));
    //        } else if ("退回修改".equals(dataStatus)) {
    //            vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.white));
    //            vh.tvStatus.setBackgroundColor(getContext().getResources().getColor(R.color.yelloy_textColor));
    //        } else {
    //            vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.white));
    //            vh.tvStatus.setBackgroundColor(getContext().getResources().getColor(R.color.black));
    //        }
    if ("草稿".equals(dataStatus)) {
      vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.red));
    } else if ("已提交".equals(dataStatus)) {
      vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.blue_textColor));
    } else if ("退回修改".equals(dataStatus)) {
      vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.yelloy_textColor));
    } else {
      vh.tvStatus.setTextColor(getContext().getResources().getColor(R.color.black));
    }

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public ProductDevelopListAdapter(Context context,
      List<ProductSalesOriginal.ProductSalesContent> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public ProductDevelopListAdapter(Context context,
      ProductSalesOriginal.ProductSalesContent[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}

